package com.zmn.mcc.permit.client.policy.impl;

import com.zmn.mcc.permit.client.model.InterceptDecisionBO;
import com.zmn.mcc.permit.client.policy.interfaces.NoPermissionPolicy;
import org.springframework.util.ReflectionUtils;

import java.lang.reflect.Field;
import java.util.Collections;

/**
 * 无权限时将属性设置为-1，且不拦截方法执行
 *
 * @author hankangshuai
 * @since 2020/06/18
 */
public class SetNegativeOnePolicyImpl implements NoPermissionPolicy {

    @Override
    public InterceptDecisionBO processNoPermission(Object noPermissionParamObj, Field noPermissionField, Object[] targetAllParams) {
        ReflectionUtils.makeAccessible(noPermissionField);
        ReflectionUtils.setField(noPermissionField, noPermissionParamObj, Collections.singletonList(-1));
        return InterceptDecisionBO.doNotIntercept();
    }

}
